package com.yuw.io.homework0803;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class MyTable_1 {
	// 封装list集合属性
	private List<Map<String, Object>> list;

	public MyTable_1() {
		init();
	}

	// 初始化学生字符串
	public void init() {
		list = new ArrayList<Map<String, Object>>();
		Scanner sc = new Scanner(System.in);
		System.out.println("是否输入信息 【yes】/【no】");
		String isChose = sc.next();
		while (true) {
			// 判断输入是否为yes
			if (!isChose.equalsIgnoreCase("yes")) {
				break;
			}
			// 定义一个map集合暂时存储学生信息
			Map<String, Object> map = new LinkedHashMap<String, Object>();
			// 存入学生表信息
			System.out.println("输入姓名:");
			String stuName = sc.next();
			map.put("姓名", stuName);
			System.out.println("输入学号：");
			int stuId = sc.nextInt();
			map.put("学号", stuId);
			System.out.println("输入成绩：");
			int stuScore = sc.nextInt();
			map.put("成绩", stuScore);
			// 将map接存入list集合当中
			list.add(map);
			System.out.println("是否继续输入：【yes】/【no】");
			isChose = sc.next();

		}

	}

	public void printAllInfo() {
		if (list != null && list.size() > 0) {
			// 定义列表list迭代器
			Iterator<Map<String, Object>> it = list.iterator();
			boolean title = true;
			while (it.hasNext()) {
				Map<String, Object> map = it.next();
				Set<String> setkey = map.keySet();
				if (title == true) {
					for (String string : setkey) {
						System.out.print("\t" + string);

					}
					title = false;
					// 输出完标题行进行换行
					System.out.println();

				}
				for (String string : setkey) {
					System.out.print("\t" + map.get(string));
				}
				// 输出完一行数据进行换行
				System.out.println();
			}

		}
	}
	

}
